package mt.dummy;

import java.util.LinkedList;
import mt.Order;
import mt.comm.ServerComm;
import mt.comm.ServerSideMessage;
import mt.comm.ServerSideMessageImp;

public class ServerCommDummy implements ServerComm {
	private LinkedList<ServerSideMessage> lista = new LinkedList<ServerSideMessage>();
	// Just to do a test to clients;
	boolean connected = false;
	boolean order_sent = false;
	boolean error_sent = false;

	// implemented just to test with JUnit
	@Override
	public void start() {
	}

	// implemented just to test with JUnit
	public void create_messageConnected() {
		lista.add(new ServerSideMessageImp(ServerSideMessage.Type.CONNECTED,
				null, "Beta"));
	}

	// implemented just to test with JUnit
	public void create_messageDisConnected() {
		lista.add(new ServerSideMessageImp(ServerSideMessage.Type.DISCONNECTED,
				null, "Beta"));
	}

	// implemented just to test with JUnit
	public void create_messageSell() {
		lista.add(new ServerSideMessageImp(ServerSideMessage.Type.NEW_ORDER,
				Order.createSellOrder("Beta", "M&M", 50, 4), "Beta"));
	}

	// implemented just to test with JUnit
	public void create_messageBuy() {
		lista.add(new ServerSideMessageImp(ServerSideMessage.Type.NEW_ORDER,
				Order.createBuyOrder("Beta", "M&M", 50, 4), "Beta"));
	}

	// implemented just to test with JUnit
	@Override
	public boolean hasNextMessage() {
		// TODO Auto-generated method stub
		return !lista.isEmpty();
	}

	// implemented just to test with JUnit
	@Override
	public ServerSideMessage getNextMessage() {
		if (hasNextMessage()) {
			return lista.pollFirst();
		} else {
			return null;
		}
	}

	// implemented just to test with JUnit
	@Override
	public void sendError(String toNickname, String error) {
		// TODO Auto-generated method stub
		error_sent = true;
	}

	// implemented just to test with JUnit
	@Override
	public boolean clientIsConnected(String nickname) {
		// TODO Auto-generated method stub
		return connected;
	}

	@Override
	public void disconnectClient(String nickname) {
		// TODO Auto-generated method stub
	}

	// implemented just to test with JUnit
	@Override
	public void sendOrder(String receiversNickname, Order order) {
		// TODO Auto-generated method stub
		order_sent = true;
	}

}
